package com.ylb.rent.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ylb.rent.dao.ApartmentStuffMapper;
import com.ylb.rent.entity.ApartmentStuff;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 import com.ylb.rent.dao.StuffMapper;
import  com.ylb.rent.entity.Stuff;
import com.ylb.rent.service.IStuffService;

/**
 * 设施Service业务层处理
 * 
 * @author ylb
 * @date 2023-06-29
 */
@Service
public class StuffServiceImpl implements IStuffService 
{
    @Autowired
    private StuffMapper stuffMapper;

    @Autowired
    private ApartmentStuffMapper apartmentStuffMapper;

    @Override
    public List<Stuff> selectListByApartmentId(Long aId) {
        ApartmentStuff apartmentStuff = ApartmentStuff.builder().apartmentId(aId).build();
        List<ApartmentStuff> apartmentStuffs = apartmentStuffMapper.selectApartmentStuffList(apartmentStuff);
//        得到stuffId集合
        List<Long> stuffIdList = apartmentStuffs.stream().map(ApartmentStuff::getStuffId).collect(Collectors.toList());
        return stuffMapper.selectBatchIds(stuffIdList);
    }

    /**
     * 查询设施
     * 
     * @param id 设施主键
     * @return 设施
     */
    @Override
    public Stuff selectStuffById(Long id)
    {
        return stuffMapper.selectStuffById(id);
    }

    /**
     * 查询设施列表
     * 
     * @param stuff 设施
     * @return 设施
     */
    @Override
    public List<Stuff> selectStuffList(Stuff stuff)
    {

        return stuffMapper.selectStuffList(stuff);
    }

    /**
     * 新增设施
     * 
     * @param stuff 设施
     * @return 结果
     */
    @Override
    public int insertStuff(Stuff stuff)
    {
        return stuffMapper.insertStuff(stuff);
    }

    /**
     * 修改设施
     * 
     * @param stuff 设施
     * @return 结果
     */
    @Override
    public int updateStuff(Stuff stuff)
    {
        return stuffMapper.updateStuff(stuff);
    }

    /**
     * 批量删除设施
     * 
     * @param ids 需要删除的设施主键
     * @return 结果
     */
    @Override
    public int deleteStuffByIds(Long[] ids)
    {
        return stuffMapper.deleteStuffByIds(ids);
    }

    /**
     * 删除设施信息
     * 
     * @param id 设施主键
     * @return 结果
     */
    @Override
    public int deleteStuffById(Long id)
    {
        return stuffMapper.deleteStuffById(id);
    }
}
